//
//  UIImage+Extend.m
//  SmallElephant
//
//  Created by Faith on 2019/1/7.
//  Copyright © 2019 Faith. All rights reserved.
//

#import "UIImage+Extend.h"

@implementation UIImage (Extend)

+ (UIImage *)imageWithName:(NSString *)name {
    return [UIImage imageWithName:name type:@"png"];
}

+ (UIImage *)imageWithName:(NSString *)name type:(NSString *)type {
    return [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:name ofType:type]];
}

+ (UIImage *)scaleImage:(UIImage *)image byFactor:(CGFloat)scaleFactor {
    // 计算缩放后的尺寸
    CGSize scaledSize = CGSizeMake(image.size.width * scaleFactor, image.size.height * scaleFactor);
    
    // 创建图形上下文，并根据缩放后的尺寸绘制图片
    UIGraphicsBeginImageContextWithOptions(scaledSize, NO, 0.0);
    [image drawInRect:CGRectMake(0, 0, scaledSize.width, scaledSize.height)];
    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return scaledImage;
}

@end
